﻿using System;
using System.Data.Entity;
using LB.Server.DAL.DomainEntitites;

namespace LB.Server.DAL.EntityFramework
{
    public class RepositoryInitializerDropCreateDatabaseIfModelChanges : DropCreateDatabaseIfModelChanges<RepositoryDataContext>
    {
        protected override void Seed(RepositoryDataContext context)
        {
            DbSeed.Seed(context);
        }
    }

    public class RepositoryInitializerDropCreateDatabaseAlways : DropCreateDatabaseAlways<RepositoryDataContext>
    {
        protected override void Seed(RepositoryDataContext context)
        {
            DbSeed.Seed(context);
        }
    }

    public class RepositoryInitializerCreateDatabaseIfNotExists : CreateDatabaseIfNotExists<RepositoryDataContext>
    {
        protected override void Seed(RepositoryDataContext context)
        {
            DbSeed.Seed(context);
        }
    }


    internal static class DbSeed
    {
        public static void Seed(RepositoryDataContext context)
        {
            // ========================= Users ================================
            var user = new User("Pomoinytskyi", "TestPassword");
            context.Users.Add(user);

            user = new User("Vitalii", "TestPassword2");
            context.Users.Add(user);

            // ========================= Books ================================

            var book = new Book { AuthorId = 1, BookId = 1, Description = "First book", Title = "How I wrote this service" };
            context.Books.Add(book);
            
            book = new Book { AuthorId = 2, BookId = 2, Description = "second book", Title = "How I wrote this service second edition" };
            context.Books.Add(book);

            context.SaveChanges();
        }
    }
}